package cn.lg.soar.system.feign.fallback;

import cn.lg.soar.system.api.enums.AccessModeEnum;
import cn.lg.soar.system.api.model.BizFileDTO;
import cn.lg.soar.system.api.model.FastUploadVO;
import cn.lg.soar.system.api.model.FileVO;
import cn.lg.soar.system.feign.FileApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 文件上传接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.system.biz.modules.general.client.FileApiClient")
public class FileApiFallbackFactory implements FallbackFactory<FileApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(FileApiFallbackFactory.class);

    @Override
    public FileApiFeign create(Throwable cause) {
        return new FileApiFeign() {

            @PostMapping("fastUpload")
            @Override
            public FileVO fastUpload(FastUploadVO vo) {
                LOGGER.error("fastUpload, vo={}", vo);
                return null;
            }

            @PostMapping("upload-dir")
            @Override
            public FileVO upload(
                    @RequestPart("file") MultipartFile file,
                    @RequestParam("directory") String directory,
                    @RequestParam("accessMode") AccessModeEnum accessMode
            ) {
                LOGGER.error("upload, directory={}，accessMode={}", directory, accessMode);
                return null;
            }

            @PostMapping("upload")
            @Override
            public FileVO upload(@RequestPart("file") MultipartFile file, @RequestParam("accessMode") AccessModeEnum accessMode) {
                LOGGER.error("upload, accessMode={}", accessMode);
                return null;
            }

            @PostMapping("saveBizFile")
            @Override
            public boolean saveBizFile(@RequestParam("bizId") Long bizId, @RequestBody Collection<BizFileDTO> bizFiles) {
                LOGGER.error("saveBizFile, bizId={}，bizFiles={}", bizId, bizFiles);
                return false;
            }

            @GetMapping("getBizFile")
            @Override
            public Map<String, List<FileVO>> getBizFile(@RequestParam("bizId") Long bizId, @RequestParam("bizTypes") Collection<String> bizTypes) {
                LOGGER.error("getBizFile, bizId={}，bizTypes={}", bizId, bizTypes);
                return Collections.emptyMap();
            }

            @PostMapping("removeBizFile")
            @Override
            public boolean removeBizFile(@RequestParam("bizId") Long bizId, @RequestParam("bizTypes") Collection<String> bizTypes) {
                LOGGER.error("removeBizFile, bizId={}，bizTypes={}", bizId, bizTypes);
                return false;
            }

        };
    }
}
